package com.example.heimaai.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import static org.springframework.ai.chat.memory.ChatMemory.CONVERSATION_ID;

@RestController
@RequiredArgsConstructor
@RequestMapping("/ai")
public class GameController {
    private final ChatClient chatClient;
    @RequestMapping(value = "/game" , produces = "text/html;charset=utf-8")
    public Flux<String> chatByFlux(String prompt, String chatId){
        return chatClient.prompt()
                .user(prompt)
                .advisors(a->a.param(CONVERSATION_ID,chatId))
                .stream()
                .content();
    }
}
